package com.rains.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.rains.beans.excel.BaseBean;
import com.rains.beans.excel.CommonBean;
import com.rains.beans.excel.SpecBean;

public class TestReadObjectFormExcelByXml {

    @SuppressWarnings("rawtypes")
    @Test
    public void testGetExcelMapUse2003Excel() throws FileNotFoundException, IOException{
        String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        File file = new File(filePath.substring(0,filePath.substring(0,filePath.length()-1).lastIndexOf("/")) + "/classes/excel/excel.xls");
        InputStream in = new FileInputStream(file);
        Map<String, List> res = ReadObjectFormExcelByXml.getExcelMap(in, "excel/commonExcelTemplate.xml");
        List list = res.get("sheet1");
        System.out.println(((BaseBean)list.get(0)).getId() + ((BaseBean)list.get(0)).getName());
        list = res.get("sheet2");
        System.out.println(((CommonBean)list.get(0)).getDesc() + ((CommonBean)list.get(0)).getBooleanStrValue());
        list = res.get("sheet3");
        System.out.println(((SpecBean)list.get(0)).getDoubleValue() );
    }
    
    @SuppressWarnings("rawtypes")
    @Test
    public void testGetExcelMapUse2010Excel() throws FileNotFoundException, IOException{
        String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        File file = new File(filePath.substring(0,filePath.substring(0,filePath.length()-1).lastIndexOf("/")) + "/classes/excel/excel.xlsx");
        InputStream in = new FileInputStream(file);
        Map<String, List> res = ReadObjectFormExcelByXml.getExcelMap(in, "excel/commonExcelTemplate.xml");
        List list = res.get("sheet1");
        System.out.println(((BaseBean)list.get(0)).getId() + ((BaseBean)list.get(0)).getName());
        list = res.get("sheet2");
        System.out.println(((CommonBean)list.get(0)).getDesc() + ((CommonBean)list.get(0)).getBooleanStrValue());
        list = res.get("sheet3");
        System.out.println(((SpecBean)list.get(0)).getDoubleValue() );
    }
}
